//
//  ZYVSModeSettingView.m
//  YiLin
//
//  Created by Zyark on 2018/6/6.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYVSModeSettingView.h"
#import "ZYModeTypeModel.h"
#import "ZYVSModeSettingItemView.h"

@interface ZYVSModeSettingView()<ZYVSModeSettingItemViewDelegate>
@property(nonatomic,strong) NSMutableArray *itemViewArray;
@end

@implementation ZYVSModeSettingView

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupVsMode];
    }
    return self;
}

-(void)setup:(NSArray *)modeArray{
    int count = 0;
    _itemViewArray = [NSMutableArray arrayWithCapacity:4];
    for (ZYModeTypeModel *model in modeArray) {
        ZYVSModeSettingItemView *itemView = [[ZYVSModeSettingItemView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height  / 4 - 5) withModeType:model.modeType];
        itemView.model = model;
        [self addSubview:itemView];
        itemView.left = 0;
        itemView.top = count * (itemView.height + 5);
        itemView.delegate = self;
        [_itemViewArray addObject:itemView];
        count ++;
    }
}

-(void)setupVsMode{
    NSArray<NSNumber *> *modeTypeArray = @[[NSNumber numberWithUnsignedInteger:ZYVSModeTypeCommon],
                                           [NSNumber numberWithUnsignedInteger:ZYVSModeTypePurification],
                                           [NSNumber numberWithUnsignedInteger:ZYVSModeTypeSleeping],
                                           [NSNumber numberWithUnsignedInteger:ZYVSModeTypeMixedWind]];
    NSArray<NSString *> *titleArray = @[LC_VS_MODE_TYPE_COMMON,
                                        LC_VS_MODE_TYPE_PURIFICATION,
                                        LC_VS_MODE_TYPE_SLEEPING,
                                        LC_VS_MODE_TYPE_MIXED_WIND];
    NSArray<NSString *> *imageNameArray = @[@"ic_vs_mode_type_common_unselected",
                                            @"ic_vs_mode_type_purification_unselected",
                                            @"ic_vs_mode_type_sleeping_unselected",
                                            @"ic_vs_mode_type_mixed_wind_unselected"];
    NSMutableArray *array = [NSMutableArray array];
    for (NSUInteger i=0; i<4; i++) {
        ZYModeTypeModel *model = [[ZYModeTypeModel alloc] init];
        model.modeType = [[modeTypeArray objectAtIndex:i] unsignedIntegerValue];
        model.title = [titleArray objectAtIndex:i];
        model.imageName = [imageNameArray objectAtIndex:i];
        [array addObject:model];
    }
    [self setup:array];
}

#pragma mark - ZYVSModeSettingItemViewDelegate
-(void)vsModeSettingItemView:(ZYVSModeSettingItemView *)vsModeSettingItemView changeWindSpeedType:(ZYWindSpeedType)speedType modeType:(ZYVSModeType)modeType{
    if([_delegate respondsToSelector:@selector(vsModeSettingView:changeWindSpeedType:modeType:)]){
        [_delegate vsModeSettingView:self changeWindSpeedType:speedType modeType:modeType];
    }
}

-(void)vsModeSettingItemView:(ZYVSModeSettingItemView *)vsModeSettingItemView doProportionClick:(UIButton *)button{
    if([_delegate respondsToSelector:@selector(vsModeSettingView:doProportionClick:)]){
        [_delegate vsModeSettingView:self doProportionClick:button];
    }
}

-(void)setValue:(NSArray *)values{
    for (ZYModeTypeModel *model in values) {
        if(NULLString(model.value)){
            continue;
        }
        NSInteger index = 0;
        if(model.modeType == ZYVSModeTypeCommon){
            //新风模式
            index = 0;
        }else if(model.modeType == ZYVSModeTypePurification){
            //舒适模式
            index = 1;
        }else if(model.modeType == ZYVSModeTypeSleeping){
            //睡眠
            index = 2;
        }else{
            //混风
            index = 3;
        }
        ZYVSModeSettingItemView *itemView = [_itemViewArray objectAtIndex:index];
        itemView.windSpeedType = model.speedType;
        
    }
}
@end
